<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <input type="checkbox"/>
    <input type="checkbox"/>
    <input type="checkbox"/>
    <input type="checkbox"/>
    <input type="checkbox"/>
    <br/><br/>
    <button id="checkAll">全选</button>
    <button id="unCheckAll">全不选</button>
    <button id="turnCheck">反选</button>
</body>
<script>
    //获取按钮和ID
    var ches = document.getElementsByTagName('input');
    var cheAll  = document.getElementById('checkAll');
    var unCheAll  = document.getElementById('unCheckAll');
    var fanXuan  = document.getElementById('turnCheck');

    //先实现全选和全不选
    cheAll.onclick = function () {
        for (var i = 0; i < ches.length; i++) {
            ches[i].checked = true;
        }
    }
    unCheAll.onclick = function () {
        for (var i = 0; i < ches.length; i++) {
            ches[i].checked = false;
        }

    }
    fanXuan.onclick = function () {
        for (var i = 0; i < ches.length; i++) {
            ches[i].checked = !ches[i].checked;//反选
        }

    }
</script>

</html>